
#include "GraphicsView.h"
#include <QWheelEvent>
#include "common.h"

//-------------------------------------

GraphicsView::GraphicsView( QGraphicsScene * s, QWidget * parent ) :
    QGraphicsView( s, parent )
{
    scene = s;
    setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
    setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
    setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
    setDragMode( QGraphicsView::ScrollHandDrag );
    setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate );
}

//-------------------------------------

void GraphicsView::wheelEvent( QWheelEvent * event )
{
    qreal scaleFactor = 1 + qreal( event->delta() )/1200;
    this->scale( scaleFactor, scaleFactor );
}

//-------------------------------------

void GraphicsView::drawBackground( QPainter * painter, const QRectF & rect )
{
    QBrush b( clBackground, Qt::SolidPattern );
    painter->fillRect( rect, b );
}

//-------------------------------------

void GraphicsView::resizeEvent( QResizeEvent * e )
{
    //scene->setSceneRect( 0, 0, size().width(), size().height() );

    QGraphicsView::resizeEvent( e );
}

//------------------------------------
